5.1 Game map analysis tests


In [ ]:
%run "../Functions/5. Game map analysis.ipynb"

Function tests


In [ ]:
allTypes = rmdf152['type'].dropna().unique()

types = ["death", "reach", "add", "craft", "remove", "select", "selectmenu"]
craftTypes = ["add", "craft", "remove", "select"]
gameTypes = ["hint", "pickup", "newfurthest", "newownrecord", "configure", "end", "complete", "restart", "start"]
webTypes = ["gotostudy", "gotomooc"]
adminTypes = ["switchtogameversion", "switchfromgameversion", "webconfigure"]

In [ ]:
allTypes

WARNING: very long test


In [ ]:
allLocatedEventsDF = filterAndLocateEvents(allTypes)

locatedEventsDF = filterAndLocateEvents(types)

craftLocatedEventsDF = filterAndLocateEvents(craftTypes)

gameLocatedEventsDF = filterAndLocateEvents(gameTypes)

webLocatedEventsDF = filterAndLocateEvents(webTypes)

adminLocatedEventsDF = filterAndLocateEvents(adminTypes)


In [ ]:
len(allLocatedEventsDF)

In [ ]:
print("minX=" + str(min(allLocatedEventsDF['x'])))
print("maxX=" + str(max(allLocatedEventsDF['x'])))
print("minY=" + str(min(allLocatedEventsDF['y'])))
print("maxY=" + str(max(allLocatedEventsDF['y'])))

In [ ]:
type(min(allLocatedEventsDF['x']))

In [ ]:
type(allLocatedEventsDF)

In [ ]:
allLocatedEventsDF.columns

In [ ]:
type(allLocatedEventsDF['x'].value_counts())

In [ ]:
allLocatedEventsDF['x'].value_counts().hist()

In [ ]:
allLocatedEventsDF['bucket'] = pd.cut(allLocatedEventsDF['x'], 10)
allLocatedEventsDF.head()

In [ ]:
newdf = allLocatedEventsDF[['bucket','x']].groupby('bucket').sum()
newdf.plot(kind='bar')

In [ ]:
allLocatedEventsDF['bucket'] = pd.cut(allLocatedEventsDF['y'], 10)
newdf = allLocatedEventsDF[['bucket','y']].groupby('bucket').sum()
#newdf.plot(kind='bar', orientation='horizontal')
newdf.plot.barh()

Plots


In [ ]:
%run "../Functions/5. Game map analysis.ipynb"

In [ ]:
constants = getConstants()
constants

In [ ]:
for event in allTypes:
    plotLocatedEvents(allLocatedEventsDF, [event])

In [ ]:
plotLocatedEvents(allLocatedEventsDF, ['end', 'configure', 'restart'])

In [ ]:
plotLocatedEvents(allLocatedEventsDF, types)

In [ ]:
plotLocatedEvents(allLocatedEventsDF, craftTypes)

In [ ]:
plotLocatedEvents(allLocatedEventsDF, gameTypes)

In [ ]:
plotLocatedEvents(allLocatedEventsDF, webTypes)

In [ ]:
plotLocatedEvents(allLocatedEventsDF, adminTypes)

Tinkering

filterAndLocateEvents


In [ ]:
rmdf152.columns

In [ ]:
#rmdf152['customData.chapter'].dropna().head()

Filter columns


In [ ]:
mapRelevantColumns = ['type', 'section', 'coordinates']
mapDF = rmdf152.loc[:,mapRelevantColumns]
len(mapDF)

In [ ]:
mapDF = mapDF.dropna()
len(mapDF)

Filter by event type


In [ ]:
mapDF = mapDF[mapDF["type"].isin(types)]
mapDF.head()

Filter by section


In [ ]:
tutorial1DF = mapDF[(mapDF['section'].str.startswith('tutorial1'))]
#sandbox2DF = mapDF[(mapDF['section'].str.startswith('sandbox'))]
tutorial1DF.head(2)

In [ ]:
len(tutorial1DF)

[x,y] coordinates


In [ ]:
tutorial1DF['x'] = tutorial1DF['coordinates']
tutorial1DF['y'] = tutorial1DF['coordinates']

In [ ]:
tutorial1DF.head(2)

In [ ]:
m = re.findall('-*\d+', '[-259, -713]')
m

In [ ]:
coordinates = re.findall('-*\d+', tutorial1DF['coordinates'][10])
coordinates

In [ ]:
subsetCount = 100
subset = tutorial1DF.head(subsetCount)
subset.index = range(0, subsetCount)

In [ ]:
f = FloatProgress(min=0, max=len(subset.index))
display(f)

for index in subset.index:
    coordinates = re.findall('-*\d+', subset['coordinates'][index])
    subset['x'][index] = coordinates[0]
    subset['y'][index] = coordinates[1]
    f.value += 1

In [ ]:
subset.head(2)

In [ ]:
types

In [ ]:
plt.figure(figsize=(15,15))
plt.axis('equal')

# c = ["black", "red", "blue", "green"]
c = ['black', 'red', 'blue', 'green', 'orange', 'purple', 'brown', 'pink', 'olive', 'cyan', ]
# a = [ 0.3, 1, 1,1 ]
a = [ 0.3, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]

scatters = {}

for i, t in enumerate(types):
  pts = subset[subset["type"] == t]
  x = pts["x"]
  y = pts["y"]

  scatters[t] = plt.plot(x, y, 'o', c=c[i], lw=0, alpha=a[i])

plt.legend([ x[0] for x in scatters.values()], list(scatters.keys()))
plt.show()

In [ ]:
_mapBackground = image.imread('../../images/map.png')

In [ ]:
type(_mapBackground)

In [ ]:
len(_mapBackground)

In [ ]:
len(_mapBackground[0])

In [ ]:
_mapBackground.shape

In [ ]:
#types = allTypes
subset = allLocatedEventsDF

In [ ]:
allLocatedEventsDF[allLocatedEventsDF['type'] == 'complete'].head(5)

In [ ]:
imgStartCoordinates = [833,432]
imgEndCoordinates = [1333,334]
constants = getConstants()
    
print(getGraphPosition(imgStartCoordinates, constants))
print(getGraphPosition(imgEndCoordinates, constants))

In [ ]:
# from image dimensions
print(getXGraphPosition(0, constants))
print(getXGraphPosition(1665, constants))
print(getYGraphPosition(890, constants))
print(getYGraphPosition(0, constants))

getConstants tinkering


In [ ]:
gameStartCoordinates = [-229,-608]
gameEndCoordinates = [450,-475]

# only for '../../images/map.tutorial1.png'
imgStartCoordinates = [833,432]
imgEndCoordinates = [1333,334]

scaleX = (gameStartCoordinates[0]-gameEndCoordinates[0])/(imgStartCoordinates[0]-imgEndCoordinates[0])
scaleY = (gameStartCoordinates[1]-gameEndCoordinates[1])/(imgStartCoordinates[1]-imgEndCoordinates[1])

offsetX = gameStartCoordinates[0] - (imgStartCoordinates[0]*scaleX)
offsetY = gameStartCoordinates[1] - (imgStartCoordinates[1]*scaleY)

newConstants = pd.Series([scaleX,scaleY,offsetX,offsetY], index=['scaleX', 'scaleY', 'offsetX', 'offsetY'])

plotLocatedEvents tinkering


In [ ]:
#constants = getConstants()
constants = newConstants

plt.figure(figsize=(18,12))

# background map image display
mapBackground = image.imread('../../images/map.tutorial1.png')

# background image dimensions
minX = 0
maxX = mapBackground.shape[1]
minY = mapBackground.shape[0]
maxY = 0

plt.imshow(mapBackground, aspect='auto', zorder=-1, \
           extent=(getXGraphPosition(minX,constants), \
                   getXGraphPosition(maxX,constants), \
                   getYGraphPosition(minY,constants), \
                   getYGraphPosition(maxY,constants)), \
           alpha=0.5)


colors = ['black', 'red', 'blue', 'green', 'orange', 'purple', 'brown', 'pink', 'olive', 'cyan', ]
alphas = [ 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, ]
scatters = {}

for i, t in enumerate(types):
  pts = subset[subset['type'] == t]
  x = pts['x']
  y = pts['y']

  scatters[t] = plt.plot(x, y, 'o', c=colors[i], lw=0, alpha=alphas[i])

plt.legend([ x[0] for x in scatters.values()], list(scatters.keys()))

# graph dimensions and extrema on tutorial1
# minX=-1152
# maxX=539
# minY=-1161
# maxY=-100
plt.xlim([-1200, 600])
plt.ylim([-1220, -20])

plt.show()